<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="app">
    <cpn :number1="num1" :number2="num2" @change-num1="change1" @change-num2="change2"></cpn>
  </div>

  <template id="cpn">
    <div>
      props:{{number1}}
      dnumb1:{{dnumber1}}
      <br>
      <!-- <input type="text" v-model="dnumber1"> -->
      <input type="text" :value="dnumber1" @input="num1Input">
      <br>
      props:{{number2}}
      dnumb1:{{dnumber2}}
      <br>
      <!-- <input type="text" v-model="dnumber2"> -->
      <input type="text" :value="dnumber2" @input="num2Input">

    </div>
  </template>

  <script>
    var vm = new Vue({
      el: '#app',
      data: {
        num1: 0,
        num2: 5

      },
      methods: {
        change1(val) {
          this.num1 = parseInt(val)
        },
        change2(val) {
          this.num2 = val - 0
        }
      },
      components: {
        cpn: {
          template: '#cpn',
          props: {
            number1: { type: Number },
            number2: { type: Number }
          },
          data() {
            return {
              dnumber1: this.number1,
              dnumber2: this.number2
            }
          },
          methods: {
            num1Input(e) {
              // 1.将input中value赋值到dunmber中
              this.dnumber1 = e.target.value
              // 2.为了让父组件可以修改值,发出一个事件
              this.$emit('change-num1', this.dnumber1)
              // 3.其他需求....同时修改dnumber2的值
            },
            num2Input(e) {
              this.dnumber2 = e.target.value
              this.$emit('change-num2', this.dnumber2)
            },
          }
        }
      }
    });
  </script>
</body>

</html>